package com.shinetech.controller;

import com.shinetech.entity.Menu;
import com.shinetech.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by joy on 2017/6/30.
 */
@RestController
@RequestMapping("/menu")
public class MenuController  extends BaseController<Menu> {


//    @RequestMapping(value = "/user/authorityTree", method = RequestMethod.GET)
//    @ResponseBody
//    public List<MenuTree> listUserAuthorityMenu(Integer parentId){
//        int userId = userBiz.getUserByUsername(getCurrentUserName()).getId();
//        try {
//            if (parentId == null) {
//                parentId = this.getSystem().get(0).getId();
//            }
//        } catch (Exception e) {
//            return new ArrayList<MenuTree>();
//        }
//        return getMenuTree(baseBiz.getUserAuthorityMenuByUserId(userId),parentId);
//    }
//
//    @RequestMapping(value = "/user/system", method = RequestMethod.GET)
//    @ResponseBody
//    public List<Menu> listUserAuthoritySystem() {
//        int userId = userBiz.getUserByUsername(getCurrentUserName()).getId();
//        return baseBiz.getUserAuthoritySystemByUserId(userId);
//    }

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/system",method = RequestMethod.GET)
    @ResponseBody
    public String getUserSystem(){
        return userService.getSystemsByUsername(getCurrentUserName());
    }

    @RequestMapping(value = "/user",method = RequestMethod.GET)
    @ResponseBody
    public String getUserMenu(@RequestParam(defaultValue = "-1") Long parentId){
        return userService.getMenusByUsername(getCurrentUserName(),parentId);
    }
}
